local yufeng = fk.CreateSkill {
  name = "1v1_mobile__yufeng",
}

Fk:loadTranslationTable{
  ["1v1_mobile__yufeng"] = "御风",
  [":1v1_mobile__yufeng"] = "出牌阶段限一次，你可以选择获得至多X点分数，然后选择至多等量的其他角色，" ..
  "其下一个准备阶段进行一次判定：若结果为黑色，其跳过出牌和弃牌阶段；若结果为红色，其跳过摸牌阶段；" ..
  "若选择角色数不足X，剩余的分数改为摸等量张牌（X为此技能发动次数+1，至少为2，至多为3）。",

  ["#1v1_mobile__yufeng"] = "御风：你可选择获得一定量分数，选择至多等量名其他角色并摸剩余量的牌",
  ["#1v1_mobile__yufeng-choose"] = "御风：选择至多 %arg 名其他角色，其下回合跳过摸牌或出牌弃牌阶段",
  ["@@1v1_mobile__yufeng"] = "御风",

  ["$1v1_mobile__yufeng1"] = "广开兮天门，纷吾乘兮玄云。",
  ["$1v1_mobile__yufeng2"] = "高飞兮安翔，乘清气兮御阴阳。",
}

yufeng:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  interaction = function(self, player)
    local maxScore = player:usedSkillTimes(yufeng.name, Player.HistoryGame) < 2 and 2 or 3
    return UI.Spin {
      from = 0,
      to = maxScore,
    }
  end,
  card_filter = Util.FalseFunc,
  prompt = "#1v1_mobile__yufeng",
  can_use = function(self, player)
    return player:usedSkillTimes(yufeng.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local score = self.interaction.data

    local tos = player.room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = score,
      prompt = "#1v1_mobile__yufeng-choose:::" .. score,
      skill_name = yufeng.name,
      cancelable = true,
    })
    if #tos > 0 then
      for _, p in ipairs(tos) do
        room:setPlayerMark(p, "@@1v1_mobile__yufeng", 1)
      end
    end
    score = score - #tos
    if score > 0 then
      player:drawCards(score, yufeng.name)
    end
  end,
})

yufeng:addEffect(fk.EventPhaseStart, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Start and player:getMark("@@1v1_mobile__yufeng") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@1v1_mobile__yufeng", 0)
    local judge = {
      who = player,
      reason = yufeng.name,
      pattern = {
        [".|.|black,red"] = "good",
        [".|.|red"] = "red",
        [".|.|black"] = "black",
        ["else"] = "bad",
      },
    }
    room:judge(judge)
    if not judge.results then return false end
    if table.contains(judge.results, "black") then
      player:skip(Player.Play)
      player:skip(Player.Discard)
    elseif table.contains(judge.results, "red") then
      player:skip(Player.Draw)
    end
  end,
})

return yufeng
